<?php include '../../authorization_check.php' ?>
<?php include '../../checkSecretaryOnly.php' ?>

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-9">
<title>View Defined Courses</title>
<SCRIPT TYPE="text/javascript" src= "../../commonutils/util/util.js"> </SCRIPT>

</head>
<style type="text/css">
/* th {text-align: right} */
</style>
<body>

<?php include 'top.html' ?>

<?php include 'notifier.php' ?>
<form name=form1 action="DeleteCourse.php" method="POST">
<p>
<table border=1 cellpadding=3>
<tr>
<th>&nbsp; </th>
<th>COURSE CODE </th>
<th>COURSE NAME </th>
<th>CREDIT </th>
<th>DESCRIPTION </th>
</tr>
<?php
require_once '../../commonutils/db/DBConnectionManager.php';

	if (isset($_POST['btnDeleteCourse']))
	{
		$courseCode = $_POST['group1']; 
		$numerrors = 0;
		$sqlquery = " select count(*) as cnt from section where courseCode = ".$courseCode;
		echo $sqlquery."<br>";
	    $result = DBConnectionManager::query($sqlquery);
	    $row = mysql_fetch_assoc($result);
	    $cnt = $row['cnt'];
	    if($cnt > 0){
	    	$numerrors = $numerrors + 1;
	    	echo "<p><font color=red> <b>* There are ".$cnt." sections opened for the course ".$courseCode." for the current semester. ";
	    	echo "You must close them first.</b> </font></p>";	
	    	echo "<p><a href=CloseSection.php> Close section page. </a></p>";
	    }
		
	    if($numerrors == 0)
	    {
			
			$sqlquery = " delete from course where courseCode = ".$courseCode;
			//echo $sqlquery."<br>";
			DBConnectionManager::query($sqlquery);
			echo "<p><font color=blue><b> You have successfully deleted the ".$courseName." course from the system. </b></font> </p>";
			echo "<p><a href=ViewDefinedCourses.php> View defined courses. </a></p>";
	    }
	}

	$sqlquery = " select courseCode, courseName, credit, description from course where programCode = ". $programCode ;
	 
	/* // echo $sqlquery."<br>";  */

	$result = DBConnectionManager::query($sqlquery);
	while($row = mysql_fetch_assoc($result)){
		echo "<tr>";
		echo "<td><input type=\"radio\" name=\"group1\" value= \"".$row['courseCode']."\">&nbsp;</td>";
		echo "<td>".$row['courseCode']." &nbsp;</td>";
		echo "<td>".$row['courseName']." &nbsp;</td>";
		echo "<td>".$row['credit']."     &nbsp;</td>";
		echo "<td>".$row['description']."&nbsp;</td>";
		echo "</tr>";		
	}

?>

</table>
</p>  

</p>

<input type="submit" name="btnDeleteCourse"  value="Delete selected course" onClick="return radioControl(group1)">
<input type="reset" value="Reset" name="btnReset">
  
</p> 

</form>

<?php include 'bottom.php' ?>

</body>


</html>